package com.ruoyi.project.projectUsers.controller;

import java.util.List;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.security.PermissionUtils;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.projectUsers.domain.ProjectUsers;
import com.ruoyi.project.projectUsers.service.IProjectUsersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目成员Controller
 *
 * @author ruoyi
 * @date 2020-05-28
 */
@Controller
@RequestMapping("/project/projectUsers")
public class ProjectUsersController extends BaseController {
  private String prefix = "project/projectUsers";

  @Autowired
  private IProjectUsersService projectUsersService;

  @RequiresPermissions("project:projectUsers:view")
  @GetMapping()
  public String projectUsers() {
    return prefix + "/projectUsers";
  }

  /**
   * 查询项目成员列表
   */
  @RequiresPermissions("project:projectUsers:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(ProjectUsers projectUsers) {
    startPage();
    List<ProjectUsers> list = projectUsersService.selectProjectUsersList(projectUsers);
    return getDataTable(list);
  }

  /**
   * 导出项目成员列表
   */
  @RequiresPermissions("project:projectUsers:export")
  @Log(title = "项目成员", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(ProjectUsers projectUsers) {
    List<ProjectUsers> list = projectUsersService.selectProjectUsersList(projectUsers);
    ExcelUtil<ProjectUsers> util = new ExcelUtil<ProjectUsers>(ProjectUsers.class);
    return util.exportExcel(list, "projectUsers");
  }

  /**
   * 新增项目成员
   */
  @GetMapping("/add")
  public String add() {
    return prefix + "/add";
  }

  /**
   * 新增保存项目成员
   */
  @RequiresPermissions("project:projectUsers:add")
  @Log(title = "项目成员", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(ProjectUsers projectUsers) {
    return toAjax(projectUsersService.insertProjectUsers(projectUsers));
  }

  /**
   * 修改项目成员
   */
  @GetMapping("/edit/{id}")
  public String edit(@PathVariable("id") Long id, ModelMap mmap) {
    ProjectUsers projectUsers = projectUsersService.selectProjectUsersById(id);
    mmap.put("projectUsers", projectUsers);
    return prefix + "/edit";
  }

  /**
   * 修改保存项目成员
   */
  @RequiresPermissions("project:projectUsers:edit")
  @Log(title = "项目成员", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(ProjectUsers projectUsers) {
    return toAjax(projectUsersService.updateProjectUsers(projectUsers));
  }

  /**
   * 删除项目成员
   */
  @RequiresPermissions("project:projectUsers:remove")
  @Log(title = "项目成员", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {
    return toAjax(projectUsersService.deleteProjectUsersByIds(ids));
  }

}
